home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
rdcf.exe
/
DOSFILES.DOC
< prev
next >
Wrap
Text File
|
1993-01-15
|
27KB
|
560 lines
A Description of the DOS File System
by Philip J. Erdelsky
PLAIN VANILLA CORPORATION
CompuServe 75746,3411
InterNet 75746.3411@compuserve.com
January 15, 1993
Copyright (c) 1993 Plain Vanilla Corporation
1. Introduction
---------------
The DOS file system is used not only by IBM PC's and compatibles, but also by
some standalone word processors that use diskettes and by a number of other
devices. Even computer systems that normally use a different file system, such
as UNIX-based workstations, also have the ability to read and write diskettes
in DOS format. All of these uses together make the DOS file system the single
most widely used file system in the world.
The file system has evolved a great deal since its origin in DOS 1.0. The
version described here is essentially that used by DOS 3.3. The large
partitions used by DOS 4.0 and later versions of DOS are not included.
This description was written in conjunction with version 2.0 of the Plain
Vanilla Reentrant DOS-Compatible File System, an implementation of the basic
DOS file system written in portable C and distributed as free software.
There are a number of details regarding the DOS file system that are
undocumented. Some of them have been filled in by experimentation; others are
simply described as undefined;
2. Block Devices
----------------
A DOS file system resides on what is generally called a block device. This is
usually a disk of some kind, but it may also be a part of regular or extended
memory that has been configured as a RAM disk.
A block device stores information in sectors of equal size. The most common
sector size is 512 bytes, which is used by all standard DOS floppy diskettes,
but some RAM disks and hard disks may use sectors containing 128, 256 or 1024
bytes.
The sectors are numbered in a very simple way. Each sector has a logical sector
number. The smallest logical sector number is zero, and the largest logical
sector number is one less than the number of sectors. Every logical sector
number between these limits is assigned to one other sector. There are no gaps
in the numbering system.
3. Mapping Sides and Tracks
---------------------------
The logical sector numbering system usually hides some complexities that must
be handled by the disk controller hardware, the disk driver software or both.
The sectors on a disk are arranged into concentric circles called tracks. Most
floppy disks have tracks on both sides. A hard disk has more than two sides,
because it consists of two or more disks, rotating in unison on the same
spindle.
Some disk controllers, especially hard disk controllers, accept logical sector
numbers and make all conversions internally; but this is not always the case.
To read or write a sector, the disk controller first moves a reading and
writing device, called a head, back or forth until it is positioned over the
track containing the desired sector. If the disk has tracks on more than one
side, there is head for each side of the disk, and they move together. The
disk controller selects the proper head by electronic switching. Finally, the
disk controller waits until the disk rotation brings the desired sector under
the head. Then it reads or writes the sector.
To convert a logical sector number L into the corresponding side, track and
sector numbers, the controller (or the software driver) usually needs the
following three numbers:
N = the number of sectors per track,
T = the number of tracks per side, and
S = the number of sides.
The tracks are usually numbered from 0 to T-1, with track 0 on the outside and
track T-1 on the inside. This puts the most frequently accessed sectors (those
with low logical sector numbers) on the outside of the disk, where sectors are
largest and the disk is the most reliable.
The sides are usually numbered from 0 to S-1, in an order determined by the
hardware design.
The sectors in a single track are numbered from 1 to N, where the disk rotation
carries them under a head in order of increasing sector number. The numbering
starts with 1, not 0. The reason for this odd convention is not clear, but it
is followed by a number of floppy disk drives, including the ones usually used
with DOS-based computers.
The assignment of logical sector numbers to sectors on a disk follows a simple
scheme with a straightforward object -- to minimize access time when the
sectors are read or written in order of ascending logical sector numbers. This
usually means minimizing the number of times the heads must be moved, since
this is by far the slowest kind of disk operation.
The formulas are as follows, where A rem B means the remainder when A is
divided by B:
sector number = L rem N + 1
side number = (L/N) rem S
track number = (L/N) / S
Logical sector number 0 is sector 1 in track 0 on side 0. Since this sector
can always be located without knowing the disk structure, it is often used to
store information about the disk structure. This is important for floppy disks,
which are removable. Many floppy disk drives can accommodate disks with more
than one format. The file system codecan read logical sector 0 to find out
how to locate other sectors.
As the logical sector number increases, the heads must be moved only when the
track number increases. This does not happen until all sectors with a
particular track number have been accessed.
The number of tracks is needed only to check the track number to see whether it
is in range. This is advisable in some cases because some disk drives may be
damaged if an attempt is made to move the heads beyond their normal range.
4. Handling Bad Sectors
-----------------------
On any large hard disk, there are apt to be some bad spots. Some hard disk
controllers can remap the bad spots and make the disk appear to be a perfect
disk with a slightly smaller capacity. This is usually done during low-level
formatting.
However, floppy disk controllers and some hard disk controllers cannot do this.
To handle most cases of this kind, the DOS file system can be set up so that
some sectors are marked as bad. No DOS file information will be written into
bad sectors. This lowers the disk capacity, but it makes imperfect disks
usable. This is usually done when the disk is formatted.
If there is a bad sector in a critical area of the disk, such as the part that
indicates which sectors are bad, the disk cannot be used to hold a DOS file
system. Fortunately, the critical area of a disk is quite small, so this is
quite unlikely.
5. Disk Partitions
------------------
The original DOS file system used 16-bit logical sector numbers, so it could
handle only file systems with at most 65535 sectors, or 32 megabytes when
512-byte sectors were used. This was the infamous 32-megabyte barrier. DOS
could use a disk with more than 65535 sectors, but it could use only 65535
sectors for its file system.
A simple solution to this problem is to divide the disk into two or more
partitions, each of which contains no more than 65535 sectors, and to treat
each partition as though it were a separate disk.
DOS 4.00 and later versions of DOS can use 32-bit logical sector numbers, so
they can handle larger partitions. This would seem to imply an 8-terabyte
maximum, but other limitations make the practical maximum smaller than that.
This document covers only partitions of 32 megabytes or less that use 16-bit
logical sector numbers.
6. The Layout of a DOS Disk
---------------------------
The sectors of a DOS disk are divided into the following groups, which are
listed in order of increasing logical sector numbers:
RESERVED SECTORS
FILE ALLOCATION TABLES
ROOT DIRECTORY
DATA AREA
HIDDEN SECTORS
The groups are described in detail in the following sections.
7. Reserved Sectors
------